package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.handmark.pulltorefresh.library.PullToRefreshWebView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Banner.ViewPagerAdapter;
import com.ydkj.a37e_mall.Classes.Model.Base.GoodsInfo;
import com.ydkj.a37e_mall.Classes.Model.Request.AddShoppingCarReq;
import com.ydkj.a37e_mall.Classes.Model.Request.AddShoppingCarResp;
import com.ydkj.a37e_mall.Classes.Model.Request.AddToCollectReq;
import com.ydkj.a37e_mall.Classes.Model.Request.CancelCollectReq;
import com.ydkj.a37e_mall.Classes.Model.Request.GetStocksReq;
import com.ydkj.a37e_mall.Classes.Model.Request.ProductDetailsReq;
import com.ydkj.a37e_mall.Classes.Model.Request.ProductParameterReq;
import com.ydkj.a37e_mall.Classes.Model.Request.TypeSelectReq;
import com.ydkj.a37e_mall.Classes.Model.Response.AddToCollectResp;
import com.ydkj.a37e_mall.Classes.Model.Response.GetStocksResp;
import com.ydkj.a37e_mall.Classes.Model.Response.ProductDetailsResp;
import com.ydkj.a37e_mall.Classes.Model.Response.ProductParameterResp;
import com.ydkj.a37e_mall.Classes.Model.Response.TypeSelectResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_post;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.Rsa;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;
import com.ydkj.a37e_mall.Resource.View.WrapContentHeightViewPager;

import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cz.msebera.android.httpclient.Header;

/**
 * Created by hong on 2016/3/21.
 * <p/>
 * 商品详细
 */
public class ProductDetails extends BaseActivity implements View.OnClickListener {

    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private LinearLayout lly_main;
    private ImageView img_back, img_shoppingcar, img_collect;
    private PullToRefreshScrollView sv_product_main;
    private WrapContentHeightViewPager vp_product_picture;
    private TextView tv_product_pic_num, tv_product_all_num, tv_product_name, tv_product_price, tv_give_integral, tv_wholesale_price, tv_min_wholesale_num,
            tv_postage, tv_sales_volume, tv_product_address, tv_select_color, tv_product_parameter, tv_collect, tv_add_shoppingCar, tv_immediately_buy;
    private LinearLayout lly_share, lly_wholesale, lly_collect;
    private RelativeLayout rly_select_color, rly_product_parameter;
    private PullToRefreshWebView webview;
    private ProductParameterAdapter productParameterAdapter;
    private List<ProductDetailsResp.ResultEntity.DataEntity> bannerList;
    private List<TypeSelectResp.ResultEntity.DataEntity> typeSelectInfoList;
    private List<ProductParameterResp.ResultEntity.DataEntity> productParameterInfoList;
    private List<GoodsInfo> shoppingCarInfoList;

    //选择颜色 尺寸 类型
    private PopupWindow pop_typeSelect;
    private ImageView img_typeselect_product;
    private TextView tv_typeselect_product_price, tv_typeselect_product_stock, tv_typeselect_color, tv_typeselect_product_color,
            tv_typeselect_size, tv_typeselect_product_size, tv_typeselect_close, tv_typeselect_add_shoppingCar,
            tv_typeselect_immediately_buy, tv_typeselect_number_less, tv_typeselect_number_add;
    private LinearLayout lly_typeselect_type;
    private EditText et_typeselect_buy_number;
    private TextView tv_typeselect_type;

    private List<Double> all_priceList;//把选中的价格加入这个list，每次点击都显示改变的价格
    private double all_type_price = 0;//每点击一个选项对应的

    //产品参数
    private PopupWindow pop_parameter;
    private ListView lv_parameter;
    private TextView tv_parameter_close;

    private int currentIndex;
    private int bannerpage;
    private String id, integral;
    private String thumb_url, price, product_name;
    private int number = 0;
    private List<Integer> idList;
    private List<Integer> format_idList;
    private List<String> typeList;
    private String secret;
    private String webview_url = "";
    private int collect_id;
    private boolean is_integral = false;
    private int stocks = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product_details);
        mActivity = this;
        ShareSDK.initSDK(mActivity);

        init();
        GetProductDeatls();
//        initWindow();//沉浸式状态栏
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);
    }

    private void init() {
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        myApplication = MyApplication.getInstance();
        if (this.getIntent().getExtras() != null) {
            id = this.getIntent().getExtras().getString("id");
            Log.e("ssss", "商品详情ID==》" + id);

//            integral = this.getIntent().getExtras().getInt("is_Integral");
        }

        typeList = new ArrayList<String>();
        idList = new ArrayList<Integer>();
        format_idList = new ArrayList<Integer>();
        all_priceList = new ArrayList<Double>();
        bannerList = new ArrayList<ProductDetailsResp.ResultEntity.DataEntity>();
        typeSelectInfoList = new ArrayList<TypeSelectResp.ResultEntity.DataEntity>();
        productParameterInfoList = new ArrayList<ProductParameterResp.ResultEntity.DataEntity>();

        lly_main = (LinearLayout) mActivity.findViewById(R.id.lly_main);
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_shoppingcar = (ImageView) mActivity.findViewById(R.id.img_shoppingcar);
        img_collect = (ImageView) mActivity.findViewById(R.id.img_collect);
        sv_product_main = (PullToRefreshScrollView) findViewById(R.id.sv_product_main);
        tv_product_name = (TextView) mActivity.findViewById(R.id.tv_product_name);
        tv_product_price = (TextView) mActivity.findViewById(R.id.tv_product_price);
        tv_give_integral = (TextView) mActivity.findViewById(R.id.tv_give_integral);
        tv_wholesale_price = (TextView) mActivity.findViewById(R.id.tv_wholesale_price);
        tv_min_wholesale_num = (TextView) mActivity.findViewById(R.id.tv_min_wholesale_num);
        tv_postage = (TextView) mActivity.findViewById(R.id.tv_postage);
        tv_sales_volume = (TextView) mActivity.findViewById(R.id.tv_sales_volume);
        tv_product_address = (TextView) mActivity.findViewById(R.id.tv_product_address);
        tv_select_color = (TextView) mActivity.findViewById(R.id.tv_select_color);
        tv_product_parameter = (TextView) mActivity.findViewById(R.id.tv_product_parameter);
        tv_collect = (TextView) mActivity.findViewById(R.id.tv_collect);
        tv_add_shoppingCar = (TextView) mActivity.findViewById(R.id.tv_add_shoppingCar);
        tv_immediately_buy = (TextView) mActivity.findViewById(R.id.tv_immediately_buy);
        lly_share = (LinearLayout) mActivity.findViewById(R.id.lly_share);
        lly_wholesale = (LinearLayout) mActivity.findViewById(R.id.lly_wholesale);
        lly_collect = (LinearLayout) mActivity.findViewById(R.id.lly_collect);
        rly_select_color = (RelativeLayout) mActivity.findViewById(R.id.rly_select_color);
        rly_product_parameter = (RelativeLayout) mActivity.findViewById(R.id.rly_product_parameter);

//        if (integral == 1) {
//            lly_wholesale.setVisibility(View.GONE);
//            tv_add_shoppingCar.setVisibility(View.GONE);
//            tv_immediately_buy.setText("立即兑换");
//        }

        sv_product_main.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
        sv_product_main.getLoadingLayoutProxy().setPullLabel("");
        sv_product_main.getLoadingLayoutProxy().setReleaseLabel("");
        sv_product_main.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                sv_product_main.setVisibility(View.GONE);
                webview.setVisibility(View.VISIBLE);
                sv_product_main.onRefreshComplete();
            }
        });

        img_back.setOnClickListener(this);
        img_shoppingcar.setOnClickListener(this);
        lly_share.setOnClickListener(this);
        rly_select_color.setOnClickListener(this);
        rly_product_parameter.setOnClickListener(this);
        lly_collect.setOnClickListener(this);
        tv_add_shoppingCar.setOnClickListener(this);
        tv_immediately_buy.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        WindowManager.LayoutParams lp;
        switch (v.getId()) {
            case R.id.img_back://返回
                finish();
                break;
            case R.id.img_shoppingcar://购物车
                startActivity(new Intent(mActivity, ShoppingCar.class));
                break;
            case R.id.lly_share://分享
                showShare(bannerList.get(0).getShare_url(), bannerList.get(0).getName());
                break;
            case R.id.rly_select_color://请选择颜色尺码类型
                //设置背景颜色变暗
                lp = getWindow().getAttributes();
                lp.alpha = 0.3f;
                getWindow().setAttributes(lp);
                initTypeSelectPopupWindow();
                pop_typeSelect.setAnimationStyle(R.style.popupWindowAnimation);
                pop_typeSelect.showAtLocation(mActivity.findViewById(R.id.lly_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                pop_typeSelect.update();
                break;

            case R.id.rly_product_parameter://产品参数
                //设置背景颜色变暗
                lp = getWindow().getAttributes();
                lp.alpha = 0.3f;
                getWindow().setAttributes(lp);
                initParameterPopupWindow();
                pop_parameter.setAnimationStyle(R.style.popupWindowAnimation);
                pop_parameter.showAtLocation(mActivity.findViewById(R.id.lly_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                pop_parameter.update();
                break;
            case R.id.lly_collect://收藏
                AddToCollect();
                break;
            case R.id.tv_add_shoppingCar://加入购物车
                if (idList.size() < typeSelectInfoList.size()) {
                    //设置背景颜色变暗
                    lp = getWindow().getAttributes();
                    lp.alpha = 0.3f;
                    getWindow().setAttributes(lp);
                    initTypeSelectPopupWindow();
                    pop_typeSelect.setAnimationStyle(R.style.popupWindowAnimation);
                    pop_typeSelect.showAtLocation(mActivity.findViewById(R.id.lly_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                    pop_typeSelect.update();
                    return;
                } else {
                    AddShoppingCar();
                }
                break;
            case R.id.tv_immediately_buy://立即购买
                if (idList.size() < typeSelectInfoList.size()) {
                    //设置背景颜色变暗
                    lp = getWindow().getAttributes();
                    lp.alpha = 0.3f;
                    getWindow().setAttributes(lp);
                    initTypeSelectPopupWindow();
                    pop_typeSelect.setAnimationStyle(R.style.popupWindowAnimation);
                    pop_typeSelect.showAtLocation(mActivity.findViewById(R.id.lly_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                    pop_typeSelect.update();
                    return;
                } else {
                    ImmediatelyBuy();
                }
                break;
        }
    }

    //初始化产品属性的popupwindow
    private void initTypeSelectPopupWindow() {
        LayoutInflater inflater = LayoutInflater.from(mActivity);
        View typelayout = inflater.inflate(R.layout.pop_type_select, null);

        img_typeselect_product = (ImageView) typelayout.findViewById(R.id.img_typeselect_product);
        tv_typeselect_product_price = (TextView) typelayout.findViewById(R.id.tv_typeselect_product_price);
        tv_typeselect_product_stock = (TextView) typelayout.findViewById(R.id.tv_typeselect_product_stock);
        tv_typeselect_color = (TextView) typelayout.findViewById(R.id.tv_typeselect_color);
        tv_typeselect_product_color = (TextView) typelayout.findViewById(R.id.tv_typeselect_product_color);
        tv_typeselect_size = (TextView) typelayout.findViewById(R.id.tv_typeselect_size);
        tv_typeselect_product_size = (TextView) typelayout.findViewById(R.id.tv_typeselect_product_size);
        tv_typeselect_close = (TextView) typelayout.findViewById(R.id.tv_typeselect_close);
        tv_typeselect_add_shoppingCar = (TextView) typelayout.findViewById(R.id.tv_typeselect_add_shoppingCar);
        tv_typeselect_immediately_buy = (TextView) typelayout.findViewById(R.id.tv_typeselect_immediately_buy);
        tv_typeselect_number_less = (TextView) typelayout.findViewById(R.id.tv_typeselect_number_less);
        tv_typeselect_number_add = (TextView) typelayout.findViewById(R.id.tv_typeselect_number_add);
        lly_typeselect_type = (LinearLayout) typelayout.findViewById(R.id.lly_typeselect_type);
        et_typeselect_buy_number = (EditText) typelayout.findViewById(R.id.et_typeselect_buy_number);

        tv_typeselect_product_stock.setText("库存" + bannerList.get(0).getStocks() + "件");

        typelayout.invalidate();
        pop_typeSelect = new PopupWindow(typelayout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置PopupWindow弹出窗体的背景
        pop_typeSelect.setBackgroundDrawable(dw);
        pop_typeSelect.setOutsideTouchable(true);
        pop_typeSelect.setFocusable(true);

//        if (is_integral == true) {
//            tv_typeselect_add_shoppingCar.setVisibility(View.GONE);
//            tv_typeselect_immediately_buy.setText("立即兑换");
//        }


        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < typeSelectInfoList.size(); i++) {
            buffer.append(typeSelectInfoList.get(i).getType() + " ");
        }
        tv_typeselect_color.setText("请选择" + " " + buffer.toString());

        //获取购买数量输入框的值
        number = Integer.parseInt(et_typeselect_buy_number.getText().toString().trim());
        //购买数量减少
        tv_typeselect_number_less.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (number == 1) {
                    return;
                } else {
                    number--;
                    et_typeselect_buy_number.setText(number + "");
                }
            }
        });
        //购买数量增加
        tv_typeselect_number_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                number++;
                et_typeselect_buy_number.setText(number + "");
            }
        });

        //立即购买
        tv_typeselect_immediately_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (idList.size() < typeSelectInfoList.size()) {
                    CommonUtil.showToast(mActivity, "请选择属性");
                } else {
                    ImmediatelyBuy();
                }
            }
        });

        //加入购物车
        tv_typeselect_add_shoppingCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (idList.size() < typeSelectInfoList.size()) {
                    CommonUtil.showToast(mActivity, "请选择属性");
                } else {
                    AddShoppingCar();
                }
            }
        });

        //关闭
        tv_typeselect_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop_typeSelect.dismiss();
                pop_typeSelect.setFocusable(false);
            }
        });


        pop_typeSelect.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (typeList.size() == typeSelectInfoList.size()) {
                    tv_select_color.setText("已选择" + " " + typeList.toString());
                } else {
                    StringBuffer buffer = new StringBuffer();
                    for (int i = 0; i < typeSelectInfoList.size(); i++) {
                        buffer.append(typeSelectInfoList.get(i).getType() + " ");
                    }
                    tv_select_color.setText("请选择" + " " + buffer.toString());
                }

                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1;
                getWindow().setAttributes(lp);
            }
        });

        //商品价格
        tv_typeselect_product_price.setText(price);
        ImageLoader.getInstance().displayImage(thumb_url, img_typeselect_product);

        et_typeselect_buy_number.setText(number + "");

        //初始化商品类型的选择
        initTypeSelect();

    }

    //初始化产品参数的popupwindow
    private void initParameterPopupWindow() {
        LayoutInflater inflater = LayoutInflater.from(mActivity);
        View parameterlayout = inflater.inflate(R.layout.pop_parameter, null);

        lv_parameter = (ListView) parameterlayout.findViewById(R.id.lv_parameter);
        tv_parameter_close = (TextView) parameterlayout.findViewById(R.id.tv_parameter_close);

//        parameterlayout.invalidate();
        pop_parameter = new PopupWindow(parameterlayout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置PopupWindow弹出窗体的背景
        pop_parameter.setBackgroundDrawable(dw);
        pop_parameter.setOutsideTouchable(true);
        pop_parameter.setFocusable(true);

        productParameterAdapter = new ProductParameterAdapter(productParameterInfoList);
        lv_parameter.setAdapter(productParameterAdapter);

        tv_parameter_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop_parameter.dismiss();
                pop_parameter.setFocusable(false);
            }
        });

        pop_parameter.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1;
                getWindow().setAttributes(lp);
            }
        });
    }

    //初始化产品属性的radiogroup、radiobutton
    private void initTypeSelect() {
        for (int i = 0; i < typeSelectInfoList.size(); i++) {
            LinearLayout typeSelectLayout = (LinearLayout) LayoutInflater.from(mActivity).inflate(R.layout.pop_type_select_radiogroup, null);
            RadioGroup typeRadioGroup = (RadioGroup) typeSelectLayout.findViewById(R.id.type_select_radiogroup_color);
            typeRadioGroup.setTag(i);
            typeRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    //checkId就是当前选中的RadioButton
                    Log.e("url", "checkid===" + checkedId);
                    for (int j = 0; j < typeSelectInfoList.get((int) group.getTag()).getDetail().size(); j++) {
                        TypeSelectResp.ResultEntity.DataEntity.DetailEntity detailEntity = typeSelectInfoList.get((int) group.getTag()).getDetail().get(j);
                        detailEntity.setIs_change(0);
                    }

                    TypeSelectResp.ResultEntity.DataEntity.DetailEntity detailEntity = typeSelectInfoList.get((int) group.getTag()).getDetail().get(checkedId);
                    detailEntity.setIs_change(1);
                    //获取所点击的数据
                    getFormatId();
                    // 每点击一个选项对应的 得到的价格
                    getPrice();
                    tv_typeselect_product_price.setText(Double.valueOf(price) + all_type_price + "");
                    tv_typeselect_color.setText(typeList.toString());
                }
            });

            //商品样式分类
            tv_typeselect_type = (TextView) typeSelectLayout.findViewById(R.id.tv_type);

            tv_typeselect_type.setText(typeSelectInfoList.get(i).getType());
            Log.e("url", "type111==" + typeSelectInfoList.get(i).getType());
            for (int j = 0; j < typeSelectInfoList.get(i).getDetail().size(); j++) {
                final TypeSelectResp.ResultEntity.DataEntity.DetailEntity detailEntity = typeSelectInfoList.get(i).getDetail().get(j);
                final RadioButton radioButton_color = (RadioButton) LayoutInflater.from(mActivity).inflate(R.layout.pop_type_select_radiobutton, null);
                radioButton_color.setId(j);
                radioButton_color.setText(detailEntity.getName());

//                final TypeSelectResp.ResultEntity.DataEntity.DetailEntity detailEntity1 = typeSelectInfoList.get(i).getDetail().get(j);
//                radioButton_color.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (detailEntity.getIs_change() == 1) {
////                            radioButton_color.setChecked(true);
//                            detailEntity.setIs_change(0);
////                            return;
//                        } else {
////                            radioButton_color.setChecked(false);
//                            detailEntity.setIs_change(1);
//                        }
//
//                    }
//                });

                if (detailEntity.getIs_change() == 1) {
                    Log.e("url", "id===" + detailEntity.getId());
                    radioButton_color.setChecked(true);
                }

                RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
                //设置内外边距
                params.leftMargin = 15;
                params.rightMargin = 15;
                radioButton_color.setLayoutParams(params);
                typeRadioGroup.addView(radioButton_color);
            }

            lly_typeselect_type.addView(typeSelectLayout);

        }
    }

    //获取所点击的数据
    public void getFormatId() {
        idList.clear();
        format_idList.clear();
        typeList.clear();
        all_priceList.clear();
        for (int i = 0; i < typeSelectInfoList.size(); i++) {
            for (int j = 0; j < typeSelectInfoList.get(i).getDetail().size(); j++) {
                TypeSelectResp.ResultEntity.DataEntity.DetailEntity detailEntity = typeSelectInfoList.get(i).getDetail().get(j);
                if (detailEntity.getIs_change() == 1) {
                    idList.add(Integer.parseInt(typeSelectInfoList.get(i).getDetail().get(j).getId()));
                    format_idList.add(Integer.parseInt(typeSelectInfoList.get(i).getDetail().get(j).getFormat_id()));
                    typeList.add(typeSelectInfoList.get(i).getDetail().get(j).getName());
                    all_priceList.add(Double.valueOf(typeSelectInfoList.get(i).getDetail().get(j).getPrice()));

                    Log.e("url", "id====" + idList.toString());
                    Log.e("url", "format_id====" + format_idList.toString());
                    Log.e("url", "type====" + typeList.toString());
                    Log.e("url", "price====" + all_priceList.toString());
                }
            }
        }

        if (format_idList.size() == typeSelectInfoList.size()) {
            Log.e("url", "all_format_id====" + format_idList.toString());
            //获取库存
            GetStocks();
        }
    }

    // 每点击一个选项对应的 得到的价格
    private double getPrice() {
        all_type_price = 0;
        for (int i = 0; i < all_priceList.size(); i++) {
            all_type_price = all_type_price + all_priceList.get(i);
        }
        Log.e("url", "all_type_price====" + all_type_price);
        return all_type_price;
    }

    private void initWebView() {
        webview = (PullToRefreshWebView) mActivity.findViewById(R.id.webview);
        webview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        // 设置WebView属性，能够执行Javascript脚本
        webview.getRefreshableView().getSettings().setJavaScriptEnabled(true);
        // 设置可以支持缩放
        webview.getRefreshableView().getSettings().setSupportZoom(true);
        // 设置出现缩放工具
        webview.getRefreshableView().getSettings().setBuiltInZoomControls(true);
        //扩大比例的缩放
        webview.getRefreshableView().getSettings().setUseWideViewPort(true);
        //自适应屏幕
        webview.getRefreshableView().getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webview.getRefreshableView().getSettings().setLoadWithOverviewMode(true);
        // 加载需要显示的网页

        Log.e("ssss", "webview_url==" + webview_url);

        webview.getRefreshableView().loadUrl(webview_url);
        // 设置Web视图
        webview.getRefreshableView().setWebViewClient(new MyWebViewClient());
        webview.getLoadingLayoutProxy().setPullLabel("");
        webview.getLoadingLayoutProxy().setReleaseLabel("");
        webview.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<WebView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<WebView> refreshView) {
                sv_product_main.setVisibility(View.VISIBLE);
                webview.setVisibility(View.GONE);

                webview.onRefreshComplete();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<WebView> refreshView) {

            }
        });

        webview.setVisibility(View.GONE);
    }

    //商品viewpager图片
    private void initBanner() {
        List<View> bannerViews = new ArrayList<View>();
        for (int i = 0; i < bannerList.get(0).getAlbum().size(); i++) {
            final ProductDetailsResp.ResultEntity.DataEntity bannerInfo = bannerList.get(0);
            RelativeLayout bannerViewLayout = (RelativeLayout) LayoutInflater.from(mActivity).inflate(R.layout.product_details_scrollview_picture, null);
            ImageView img_product_picture = (ImageView) bannerViewLayout.findViewById(R.id.img_product_picture);

            ImageLoader.getInstance().displayImage(bannerInfo.getAlbum().get(i), img_product_picture);
            Log.e("rul", "getThumb====" + bannerList.size());
            Log.e("rul", "getThumb====" + bannerInfo.getAlbum().get(i));

            bannerViews.add(bannerViewLayout);
        }
        // 初始化banner
        tv_product_pic_num = (TextView) mActivity.findViewById(R.id.tv_product_pic_num);
        tv_product_all_num = (TextView) mActivity.findViewById(R.id.tv_product_all_num);

        if (bannerList.get(0).getAlbum().size() == 0) {
            tv_product_pic_num.setText("0");
        }

        tv_product_all_num.setText("" + bannerList.get(0).getAlbum().size());

        currentIndex = 0;
        bannerpage = 1;
        vp_product_picture = (WrapContentHeightViewPager) findViewById(R.id.vp_product_picture);
        // 初始化Adapter
        ViewPagerAdapter bannerPagerAdapter = new ViewPagerAdapter(bannerViews);
        vp_product_picture.setAdapter(bannerPagerAdapter);
        vp_product_picture.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int arg0) {
                // TODO Auto-generated method stub
                currentIndex = arg0;
                int bannerIndex = arg0 + 1; // bannerIndex为第几张banner
                tv_product_pic_num.setText("" + bannerIndex);
                Log.e("bannerList.size()", "bannerList.size()==" + bannerList.size());
                bannerpage = arg0 + 1;
                if (bannerpage == bannerList.size()) {
                    bannerpage = 0;
                }
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub
                vp_product_picture.getParent()
                        .requestDisallowInterceptTouchEvent(true);
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub
            }
        });
    }

    private class ProductParameterAdapter extends BaseAdapter {
        private List<ProductParameterResp.ResultEntity.DataEntity> parameterInfoList;

        private ProductParameterAdapter(List<ProductParameterResp.ResultEntity.DataEntity> dataEntityList) {
            if (dataEntityList == null) {
                dataEntityList = new ArrayList<ProductParameterResp.ResultEntity.DataEntity>();
            }
            parameterInfoList = dataEntityList;
        }

        @Override
        public int getCount() {
            return parameterInfoList.size();
        }

        /**
         * 获得某一位置的数据
         */
        @Override
        public ProductParameterResp.ResultEntity.DataEntity getItem(int position) {
            return parameterInfoList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(
                        R.layout.product_details_parameter_listitem, null);
                vh = new ViewHolder();
                vh.tv_parameter_name = (TextView) convertView.findViewById(R.id.tv_parameter_name);
                vh.tv_parameter_content = (TextView) convertView.findViewById(R.id.tv_parameter_content);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);

            vh.tv_parameter_name.setText(productParameterInfoList.get(position).getType());

            Log.e("url", "productParameterInfoList==" + productParameterInfoList.get(position).getType());
            Log.e("url", "size==" + productParameterInfoList.get(position).getDetail().size());
            for (int i = 0; i < productParameterInfoList.get(position).getDetail().size(); i++) {
                if (i == 0) {
                    vh.tv_parameter_content.setText(vh.tv_parameter_content.getText() + productParameterInfoList.get(position).getDetail().get(i).getName());
                } else {
                    vh.tv_parameter_content.setText(vh.tv_parameter_content.getText() + "," + productParameterInfoList.get(position).getDetail().get(i).getName());
                }
                Log.e("url", "type_name==" + productParameterInfoList.get(position).getDetail().get(i).getName());
            }
            return convertView;
        }

        private class ViewHolder {
            public TextView tv_parameter_name, tv_parameter_content;
        }
    }

    //获取商品详情
    private void GetProductDeatls() {
//        number=0;
        CustomProgressDialog.createDialog(mActivity).Show();
        ProductDetailsReq req = new ProductDetailsReq();
        req.setId(id);
        if (!sharedPreferencesUtil.getAccessToken().equals("")) {
            params.put("token", sharedPreferencesUtil.getAccessToken());
        }

        try {
            String source = req.getSecret();
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(source);
            Log.e("url", "source==" + source);

        } catch (Exception e) {
            e.printStackTrace();
        }

        params.put("secret", secret);


        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("url", "productDetail_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    ProductDetailsResp resp = GsonImpl.get().toObject(response.toString(), ProductDetailsResp.class);
                    bannerList.clear();
                    bannerList.add(resp.getResult().getData());
                    initBanner();

                    tv_product_name.setText(resp.getResult().getData().getList_title());
//                    if (resp.getResult().getData().getIs_integral() == 0) {
//                        tv_product_price.setText("¥ " + resp.getResult().getData().getPrice());
//                        tv_give_integral.setText("(赠送" + resp.getResult().getData().getIntegral() + "积分)");
//                        tv_wholesale_price.setText("批发价格 ¥" + resp.getResult().getData().getWholesales_price() + "  (赠送" + resp.getResult().getData().getWholesales_integral() + "积分)");
//                        tv_min_wholesale_num.setText("最低批发数：" + resp.getResult().getData().getWholesales_num());
//                    } else {
//                    is_integral = true;
                    tv_product_price.setText(resp.getResult().getData().getPrice());
                    tv_give_integral.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
                    tv_give_integral.setText(resp.getResult().getData().getMarket_price());

//                        lly_wholesale.setVisibility(View.GONE);
//                        tv_add_shoppingCar.setVisibility(View.GONE);
//                        tv_immediately_buy.setText("立即兑换");
//                    }
                    Log.e("url", number + "");

//                    if (resp.getResult().getData().getFree_shipping().equals("")) {
//                        tv_postage.setText("邮费到付");
//                    } else {
//                        if (number <= Integer.parseInt(resp.getResult().getData().getFree_shipping()) || number == 0) {
//                            tv_postage.setText("邮费到付");
//                        } else {
                    tv_postage.setText("包邮");
//                        }
//                    }

                    tv_sales_volume.setText("销量" + resp.getResult().getData().getSales() + "笔");
//                    tv_product_address.setText(resp.getResult().getData().getOrigin());
                    thumb_url = resp.getResult().getData().getList_thumb();
                    price = resp.getResult().getData().getPrice();
                    product_name = resp.getResult().getData().getName();
                    webview_url = resp.getResult().getData().getDetail_url();

                    if (resp.getResult().getData().isIs_favor() == true) {
                        tv_collect.setText("已收藏");
                        tv_collect.setTextColor(getResources().getColor(R.color.A333333));
                        img_collect.setImageDrawable(getResources().getDrawable(R.mipmap.collect_red));
                    }

                    GetTypeSelect();
//                    GetProductParameter();
                    initWebView();
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败1");
            }
        });
    }

    //获取颜色尺码类型
    private void GetTypeSelect() {
        CustomProgressDialog.createDialog(mActivity).Show();
        TypeSelectReq req = new TypeSelectReq();
        req.setId(id);
        try {
            String source = req.getString();
            Rsa rsa = new Rsa();
            Log.e("url", "source==" + source);
            secret = rsa.encryptByPublic(source);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestParams params = new RequestParams();

        params.put("secret", secret);
        Log.e("url", "id==" + req.getId());
        String url = Const.COMMON_ADDRESS + req.urlString();
        Log.e("url", "url==" + url);
        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("ssss", "typeSelect_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    TypeSelectResp resp = GsonImpl.get().toObject(response.toString(), TypeSelectResp.class);
                    typeSelectInfoList.addAll(resp.getResult().getData());

                    StringBuffer buffer = new StringBuffer();
                    for (int i = 0; i < typeSelectInfoList.size(); i++) {
                        buffer.append(typeSelectInfoList.get(i).getType() + " ");
                    }
                    tv_select_color.setText("请选择" + " " + buffer.toString());
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败2");
                Log.e("url", "statusCode==" + statusCode + "  responseString==" + responseString);
            }
        });
    }

    //获取库存
    private void GetStocks() {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < format_idList.size(); i++) {
            if (i == format_idList.size() - 1) {
                buffer.append(format_idList.get(i));
            } else {
                buffer.append(format_idList.get(i) + ",");
            }
        }
        Log.e("ssss", "buffer.toString()==>" + buffer.toString());
        Log.e("ssss", "id==>" + id);
//        Log.e("ssss", "uuid==>" + myApplication.getDataEntity().getUuid());
        GetStocksReq req = new GetStocksReq();
        req.setId(id);
        req.setFormat_id_str(buffer.toString());
        req.setUuid(myApplication.getDataEntity().getUuid());
        String url = Const.COMMON_ADDRESS + req.urlString();
        RequestParams params = new RequestParams();
        try {
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(req.getString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        params.put("secret", secret);
        Log.e("url", "params==" + params);
        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "stocks_json==" + response.toString());
                if (errno.equals("000")) {
                    GetStocksResp resp = GsonImpl.get().toObject(response.toString(), GetStocksResp.class);
                    tv_typeselect_product_stock.setText("库存" + resp.getResult().getData().get(0).getStock() + "件");
                    stocks = Integer.parseInt(resp.getResult().getData().get(0).getStock());
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });

    }

    //获取产品参数 暂时不需要
    private void GetProductParameter() {
        ProductParameterReq req = new ProductParameterReq();
        req.setId(id);
        RequestParams params = new RequestParams();
        params.put("id", req.getId());
        params.put("secret", req.getSecret());
        String url = Const.COMMON_ADDRESS + req.urlString();
        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "paratemer_json==" + response);
                if (errno.equals("000")) {
                    ProductParameterResp resp = GsonImpl.get().toObject(response.toString(), ProductParameterResp.class);
                    productParameterInfoList.addAll(resp.getResult().getData());
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }

    //添加收藏
    private void AddToCollect() {
        CustomProgressDialog.createDialog(mActivity).Show();
        AddToCollectReq req = new AddToCollectReq();
        req.setId(id);
        req.setUuid(myApplication.getDataEntity().getUuid());
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());

        params.put("secret", req.getSecret());
        Log.e("ssss", "addToCollect_secret==>" + req.getSecret());
        Async_http_post.post(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("url", "addToCollect_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    tv_collect.setText("已收藏");
                    tv_collect.setTextColor(getResources().getColor(R.color.A333333));
                    img_collect.setImageDrawable(getResources().getDrawable(R.mipmap.collect_red));
//                    sharedPreferencesUtil.setCollect(1);//“1”代表收藏
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 4);
                    Log.e("url", "errmsg==" + errmsg);
                } else {
                    AddToCollectResp resp = GsonImpl.get().toObject(response.toString(), AddToCollectResp.class);
//                    collect_id = resp.getData().getFavor_id();
//                    CancelCollect(id);//取消收藏
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败3");
            }
        });
    }

    //取消收藏
    private void CancelCollect(String collect_id) {
        AsyncHttpClient client = new AsyncHttpClient();
        CancelCollectReq req = new CancelCollectReq();
        req.setId(collect_id);

        RequestParams params = new RequestParams();
        params.put("uuid", myApplication.getDataEntity().getUuid());
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());

        Log.e("url", "params==" + params);
        client.put(Const.COMMON_ADDRESS + req.urlString() + myApplication.getDataEntity().getUuid(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    tv_collect.setText("收藏");
                    tv_collect.setTextColor(getResources().getColor(R.color.A999999));
                    img_collect.setImageDrawable(getResources().getDrawable(R.mipmap.collect_default));
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 1);
                    Log.e("url", "errmsg==" + errmsg);
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CommonUtil.showToast(mActivity, "网络连接失败4");
            }
        });
    }

    //加入购物车
    public void AddShoppingCar() {

        Log.e("url", "stocks==" + stocks);
        if (stocks <= 0) {
            CommonUtil.showToast(mActivity, "亲，没有库存了");
            return;
        }

        CustomProgressDialog.createDialog(mActivity).Show();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < format_idList.size(); i++) {
            if (i == format_idList.size() - 1) {
                buffer.append(format_idList.get(i));
            } else {
                buffer.append(format_idList.get(i) + ";");
            }
        }

        AddShoppingCarReq req = new AddShoppingCarReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setId(id);

        Log.e("url", "getActivity_id==" + bannerList.get(0).getActivity_id());
        if (bannerList.get(0).getActivity_id().equals("")) {
            req.setActivity_id("");
        } else {
            req.setActivity_id(bannerList.get(0).getActivity_id());
        }

        Log.e("ssss", "Format==>" + buffer.toString());
        req.setFormat(buffer.toString());
        req.setNum(number + "");


        String url = Const.COMMON_ADDRESS + req.urlString();

        RequestParams params = new RequestParams();

        params.put("token", sharedPreferencesUtil.getAccessToken());

        try {

            Rsa rsa = new Rsa();
            if (req.getActivity_id().equals("")) {
                secret = rsa.encryptByPublic(req.getString1());
                Log.e("url", "source==" + req.getString1());

            } else {
                secret = rsa.encryptByPublic(req.getString());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        params.put("secret", secret);
        Log.e("url", "params==" + params.toString());
        Async_http_post.post(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.e("url", "addShoppingCar_json==" + response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    shoppingCarInfoList = new ArrayList<GoodsInfo>();
                    AddShoppingCarResp resp = GsonImpl.get().toObject(response.toString(), AddShoppingCarResp.class);

                    shoppingCarInfoList.add(resp.getResult().getData());
                    CommonUtil.showToast(mActivity, errmsg);
                    pop_typeSelect.dismiss();
                    pop_typeSelect.setFocusable(false);
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 2);
                    Log.e("url", "errmsg==" + errmsg);
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Log.e("Tag", "statusCode.. " + statusCode);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败5");
            }
        });
    }

    //立即购买
    private void ImmediatelyBuy() {
        Log.e("url", "stocks==" + stocks);
        if (stocks <= 0) {
            CommonUtil.showToast(mActivity, "亲，没有库存了");
            return;
        }

        CustomProgressDialog.createDialog(mActivity).Show();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < format_idList.size(); i++) {
            if (i == format_idList.size() - 1) {
                buffer.append(format_idList.get(i));
            } else {
                buffer.append(format_idList.get(i) + ";");
            }
        }

        AddShoppingCarReq req = new AddShoppingCarReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setId(id);

        Log.e("url", "getActivity_id==" + bannerList.get(0).getActivity_id());
        if (bannerList.get(0).getActivity_id().equals("")) {
            req.setActivity_id("");
        } else {
            req.setActivity_id(bannerList.get(0).getActivity_id());
        }

        Log.e("ssss", "Format==>" + buffer.toString());
        req.setFormat(buffer.toString());
        req.setNum(number + "");


        String url = Const.COMMON_ADDRESS + req.urlString();

        RequestParams params = new RequestParams();

        params.put("token", sharedPreferencesUtil.getAccessToken());

        try {

            Rsa rsa = new Rsa();
            if (req.getActivity_id().equals("")) {
                secret = rsa.encryptByPublic(req.getString1());
                Log.e("url", "source==" + req.getString1());

            } else {
                secret = rsa.encryptByPublic(req.getString());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        params.put("secret", secret);
        Log.e("url", "params==" + params.toString());
        Async_http_post.post(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.e("url", "addShoppingCar_json==" + response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    shoppingCarInfoList = new ArrayList<GoodsInfo>();
//                    GoodsInfo resp = GsonImpl.get().toObject(response.toString(), GoodsInfo.class);
                    AddShoppingCarResp resp = GsonImpl.get().toObject(response.toString(), AddShoppingCarResp.class);

                    shoppingCarInfoList.add(resp.getResult().getData());
//                    shoppingCarInfoList.add(resp);

                    Intent intent = new Intent(mActivity, ConfirmationOrder.class);
                    intent.putExtra("intentList", (Serializable) shoppingCarInfoList);
                    startActivity(intent);

                    pop_typeSelect.dismiss();
                    pop_typeSelect.setFocusable(false);
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 2);
                    Log.e("url", "errmsg==" + errmsg);
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Log.e("Tag", "statusCode.. " + statusCode);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败6");
            }
        });
    }


    //分享  11
    private void showShare(String url, String text) {
        ShareSDK.initSDK(mActivity);

        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle(text);
        // titleUrl是标题的网络链接，QQ和QQ空间等使用
        oks.setTitleUrl(url);
        // text是分享文本，所有平台都需要这个字段
        oks.setText(text);
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl(url);
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl(url);

        // 启动分享GUI
        oks.show(mActivity);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                break;
            case 2:
                if (resultCode == Activity.RESULT_OK) {
//                    AddShoppingCar();
                }
                break;
            case 3:
                if (resultCode == Activity.RESULT_OK) {
//                    AddShoppingCarToConfirmationOrder();
                }
                break;
            case 4:
                if (resultCode == Activity.RESULT_OK) {
                    AddToCollect();
                }
                break;
        }
    }


    // 监听 所有点击的链接，如果拦截到我们需要的，就跳转到相对应的页面。
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }

        public void onPageStarted(WebView view, String url, Bitmap favicon) {

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            view.getSettings().setJavaScriptEnabled(true);
            super.onPageFinished(view, url);
        }
    }
}
